﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _070.EFCore一对多
{
	public class MyDbContext : DbContext
	{
		public DbSet<Article> Articles { get; set; }
		public DbSet<Comment> Comments { get; set; }


		protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
		{
			base.OnConfiguring(optionsBuilder);
			string connStr = "Server=10.34.10.12;Database=fanzhineng;User ID=root;Password=Ziyang0505;";
			optionsBuilder.UseMySql(connStr, new MySqlServerVersion(new Version(8, 0, 32)));
			optionsBuilder.LogTo(msg => {
				if (!msg.Contains("CommandExecuted"))
				{
					return;
				}
				Console.WriteLine(msg);
			});
		}
		protected override void OnModelCreating(ModelBuilder modelBuilder)
		{
			base.OnModelCreating(modelBuilder);
			// 从当前程序集加载所有的IEntityTypeConfiguration
			modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);

		}
	}
}
